package test.hex;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import java.math.BigInteger;

public class EncodeUtil {
    public static String hex2Oct(String hex) throws DecoderException {
        try {
            return hex == null ? null : new BigInteger(Hex.decodeHex(hex.toCharArray())).toString();
        } catch (DecoderException e) {
            throw new DecoderException(e);
        }
    }

    public static String oct2Hex(String oct) {
        return oct == null ? null : new String(Hex.encodeHex(new BigInteger(oct).toByteArray())).toUpperCase();
    }

}
